//
//  GoodsCenterHeaderView.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/24.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "GoodsCenterHeaderView.h"

@interface GoodsCenterHeaderView ()

@property (nonatomic, weak)UIView * whiteView;
@property (nonatomic, weak)UILabel * amountLabel;
@property (nonatomic, weak)UIButton * detailsButton;
@property (nonatomic, weak)UILabel * moneyLabel;
@property (nonatomic, weak)UIButton * verifyButton;
@property (nonatomic, weak)UIView * blackView;
@property (nonatomic, weak)UILabel * verifyLabel;
@property (nonatomic, weak)UIImageView * verifyImageView;
@property (nonatomic, copy)NSString * money;

@end

@implementation GoodsCenterHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self loadData];
        [self setupUI];
    }
    
    return self;
}

- (void)loadData{
    
    [[ZRNetworkTool sharedTool] getMerchantsBillResultWithBlock:^(BOOL success, id responseData) {
        
        if (success) {
            
            self.moneyLabel.text = [NSString stringWithFormat:@"￥%@",responseData[@"data"]];
            self.money = [NSString stringWithFormat:@"%@",responseData[@"data"]];
        }
    }];
}

- (void)setupUI{
    
    self.backgroundColor = ColorWithRGB(0xF8F9FA);
    
    UIView * whiteView = [UIView new];
    
    whiteView.backgroundColor = ZRWhiteColor;
    whiteView.userInteractionEnabled = YES;
    whiteView.layer.cornerRadius = 5 * SCREENH6;
    whiteView.layer.masksToBounds = YES;
    
    self.whiteView = whiteView;
    
    [self addSubview:self.whiteView];
    
    
    UILabel * amountLabel = [UILabel new];
    
    amountLabel.textColor = ZRBlackColor;
    amountLabel.text = @"账户";
    amountLabel.font = [UIFont boldSystemFontOfSize:14 * SCREENH6];
    
    self.amountLabel = amountLabel;
    
    [self.whiteView addSubview:self.amountLabel];
    
    
    UILabel * moneyLabel = [UILabel new];
    
    moneyLabel.textColor = ZRBlackColor;
    moneyLabel.text = @"$10011.50";
    moneyLabel.font = [UIFont boldSystemFontOfSize:30 * SCREENH6];
    
    self.moneyLabel = moneyLabel;
    
    [self.whiteView addSubview:self.moneyLabel];
    
    
    UIButton * detailsButton = [UIButton new];
    
    [detailsButton setTitle:@"详情" forState:UIControlStateNormal];
    [detailsButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [detailsButton addTarget:self action:@selector(clickDetailsButton:) forControlEvents:UIControlEventTouchUpInside];;
    detailsButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    self.detailsButton = detailsButton;
    
    [self.whiteView addSubview:self.detailsButton];
    
    
    UIButton * verifyButton = [UIButton new];
    
    verifyButton.backgroundColor = ColorWithRGB(0xFFE055);
    verifyButton.layer.cornerRadius = 5 * SCREENH6;
    verifyButton.layer.masksToBounds = YES;
    [verifyButton addTarget:self action:@selector(clickDetailsButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.verifyButton = verifyButton;
    
    [self addSubview:self.verifyButton];
    
    UIView * blackView = [UIView new];
    
    blackView.backgroundColor = ZRBlackColor;
    blackView.layer.cornerRadius = 25 * SCREENH6;
    blackView.layer.masksToBounds = YES;
    blackView.userInteractionEnabled = NO;
    
    self.blackView = blackView;
    
    [self.verifyButton addSubview:self.blackView];
    
    UILabel * verifyLabel = [UILabel new];
    
    verifyLabel.text = @"提现";
    verifyLabel.textColor = ZRBlackColor;
    verifyLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    verifyLabel.userInteractionEnabled = NO;
    
    self.verifyLabel = verifyLabel;
    
    [self.verifyButton addSubview:self.verifyLabel];
    
    
    UIImageView * verifyImageView = [UIImageView new];
    
    verifyImageView.image = [UIImage imageNamed:@"money(1)"];
    verifyImageView.userInteractionEnabled = NO;
    
    self.verifyImageView = verifyImageView;
    
    [self.verifyButton addSubview:self.verifyImageView];
}


- (void)layoutSubviews{
    
    [self.whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self).offset(10 * SCREENH6);
        make.width.mas_equalTo(235 * SCREENH6);
        make.height.mas_equalTo(80 * SCREENH6);
    }];
    
    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.whiteView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.whiteView).offset(10 * SCREENH6);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.amountLabel);
        make.top.mas_equalTo(self.amountLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.detailsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.whiteView).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.amountLabel);
    }];
    
    [self.verifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.mas_equalTo(self.whiteView);
        make.leading.mas_equalTo(self.whiteView.mas_trailing).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
    }];
    
    [self.blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.verifyButton);
        make.top.mas_equalTo(self.verifyButton).offset(10 * SCREENH6);
        make.width.height.mas_equalTo(50 * SCREENH6);
    }];
    
    [self.verifyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.blackView);
        make.centerY.mas_equalTo(self.blackView);
    }];
    
    [self.verifyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.blackView.mas_bottom).offset(3 * SCREENH6);
        make.centerX.mas_equalTo(self.blackView);
    }];
}


//点击详情
- (void)clickDetailsButton:(UIButton *)button{
    
    NSString * type;
    
    if (button == self.verifyButton) {
        
        type = @"verify";
    }else{
        
        type = @"detail";
    }
    
    if (self.goodsCenterHeaderViewDelegate && [self.goodsCenterHeaderViewDelegate respondsToSelector:@selector(clickHeaderItemButton: WithMoney:)])
    {
        [self.goodsCenterHeaderViewDelegate clickHeaderItemButton:type WithMoney:self.money];
    }
}

@end
